package cn.simon.controller;

import cn.simon.model.BiliUser;
import cn.simon.service.Impl.LoginServiceImpl;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.concurrent.TimeUnit;

@WebServlet(name = "Servlet", value = "/check")
public class Bili_AjaxController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String username = request.getParameter("name");

        LoginServiceImpl loginService = new LoginServiceImpl();
        BiliUser user = loginService.getPaword(username);
        PrintWriter writer = response.getWriter();
        if(user != null)
            writer.write("该用户名已被注册");
        else
            writer.write("该用户名可用");
    }
}
